<template>
	<view class="box">
		<view>
			<drawer :show="isDrawerOpen" @close="closeDrawer"></drawer>
		</view>
		<view>
			<languageMask :show="isOpenMask" @close="closeMask" @languageChanged="refreshLanguage"></languageMask>
		</view>
		<view class="head">
			<view style="display: flex;align-items: center;">
				<image src="../../static/qukuailian2_slices/danlieliebiao.png" class="list" @click="openDrawer"></image>
				<image src="../../static/caifubeifen_slices/lujing9.png" mode="" class="back" @click="toDetails">
				</image>
			</view>
			<view class="head-title">
				<view class="vtitle">{{$data.$language.ewsandinfo}}</view>
			</view>
			<view class="right-head">
				<image src="../../static/qianbaobeifen2_slices/diqiugenghuan.png" mode="" class="language" @click="openMask">
				</image>
			</view>
		</view>
		<view class="ritsview">
			<rich-text :nodes="setDetail(richTextNodes)"></rich-text>
		</view>
		<view style="width: 100%;height: 50rpx;background-color: #fff;">
			
		</view>
	</view>
</template>

<script>
	import htmlParser from '@/api/html-parser.js'
	import drawer from "../../my-components/drawer/drawer.vue"
	import languageMask from "../../my-components/languageMask/languageMask.vue"
	import zhCN from '@/locales/zh-CN.js'
	import enUS from '@/locales/en-US.js'
	import trCN from '@/locales/tr-CN.js'
	import {
		articleData
	} from '@/api/index.js';
	export default {
		data() {
			return {
				// $language: uni.getStorageSync('locale') == 'en-US' ? enUS : zhCN,
				isDrawerOpen: false,
				isOpenMask: false,
				richTextNodes:'',
				url:'',

			}
		},
		onReachBottom() {  
		},
		onLoad(option) {
			var translate = uni.getStorageSync('locale')
			if(translate=='en-US'){
				this.$data.$language = enUS
			}else if(translate=='zh-CN'){
				this.$data.$language = zhCN
			}else{
				this.$data.$language = trCN
			}
			var url = location.href
			// this.longinhs(location.href)
			// var url = 'http://wonewoo.com/#/pages/ewsand/ewsand?id=2'
			//声明参数字典
			let requestDic = {};
			//确定URL中包含 ？ 
			if (url.indexOf("?") !== -1) {
				//返回 ？ 后面的字符串
				let str = url.substr(url.indexOf("?") + 1);
				//通过 & 符号分割字符串，获取参数数组
				let strArray = str.split("&");
				//遍历参数数组
				for (let i = 0; i < strArray.length; i++) {
					//把遍历到的每一个元素再以 = 分割，分割后第0为作为key，第一位作为value 存放到字典中
					requestDic[strArray[i].split("=")[0]] = decodeURI(strArray[i].split("=")[1]);
				}
			}
			console.log(requestDic)
			// const data = JSON.parse(decodeURIComponent(option.data))
			this.articleDataList(requestDic.id)
		},
		methods: {
			setDetail(str){
				if(str){
					return htmlParser(str)
				}
			},
			articleDataList(id){
				articleData({
						id: id,
					},
					(data) => {
						// 处理成功返回的数据
						// console.log(data,'123456')
						this.richTextNodes = data.content
						
					},
					(errorMsg) => {
						// 处理请求失败或错误的情况
						console.error(errorMsg);
					}
				);
			},
			refreshLanguage(locale) {
				if (locale === 'zh-CN') {
					this.$language = zhCN
				} else if (locale === 'en-US') {
					this.$language = enUS
				}else{
					  this.$language = trCN
				  }
				uni.reLaunch({
					url: '/pages/Recharge/Recharge'
				});

			},
			toDetails() {
				uni.navigateTo({
					url: '/pages/index/index'
				})
			},
			openDrawer() {
				this.isDrawerOpen = true
			},
			closeDrawer() {
				this.isDrawerOpen = false
			},
			openMask() {
				this.isOpenMask = true
			},
			closeMask() {
				this.isOpenMask = false; // 遮罩层guanbi事件处理
			},
		},

		components: {
			drawer,
			languageMask
		}
	}
</script>

<style lang="less">
	.box {
		width: 750rpx;
	}

	.head {
		padding: 40rpx;
	}

	.headline {
		display: flex;
	}
	.images{
		width: 100%;
		height: 246rpx;
		padding: 0 42rpx;
	}
	.ritsview{
		min-height: 800rpx;
		background-color: #fff;
	}
	.title {
		width: 164rpx;
		height: 48rpx;
		font-size: 34rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #000000;
		line-height: 48rpx;
		margin: 28.85rpx 0 0 158rpx;
	}

</style>